package com.avic.rong.goodsSort.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.goodsSort.activity.secondListActivity.GoodsSortBzActivity;
import com.avic.rong.goodsSort.bean.GoodsSortItemBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Chenjiaxin on 2019/7/15 20:22
 * E-Mail Address：16601203965@163.com
 */
public class GoodsBzTabRvAdapter extends RecyclerView.Adapter<GoodsBzTabRvAdapter.GoodsBzTitleViewHolder> {
    private Context context;
    private List<GoodsSortItemBean.InternalListBean> list = new ArrayList<>();
    private LayoutInflater inflater;
//    private int itemCount = 4;
    private View view;
    private String state;

    public GoodsBzTabRvAdapter(Context context,String state) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.state = state;
    }

    public void setList(List<GoodsSortItemBean.InternalListBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public GoodsBzTitleViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        view = inflater.inflate(R.layout.view_goods_rv_item, viewGroup, false);
        return new GoodsBzTitleViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GoodsBzTitleViewHolder holder, int i) {
        if (state.equals("zb")){
            holder.tv.setText(list.get(i).getCatName());
            holder.tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, GoodsSortBzActivity.class);
                    intent.putExtra("keyword",list.get(i).getCatName());
                    Log.e("cjx","keyWord:"+list.get(i).getCatName());
                    context.startActivity(intent);
                }
            });
        }else if (state.equals("gb")){
            holder.tv.setText(list.get(i).getCatName());
            holder.tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, GoodsSortBzActivity.class);
                    intent.putExtra("keyword",list.get(i).getCatName());
                    Log.e("cjx","keyWord:"+list.get(i).getCatName());
                    context.startActivity(intent);
                }
            });
        }else if (state.equals("gjb")){
            holder.tv.setText(list.get(i).getCatName());
            holder.tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, GoodsSortBzActivity.class);
                    intent.putExtra("keyword",list.get(i).getCatName());
                    Log.e("cjx","keyWord:"+list.get(i).getCatName());
                    context.startActivity(intent);
                }
            });
        }

    }

    @Override
    public int getItemCount() {
//        if (list.size() > 4) {
//            return itemCount;
//        } else {
            return list.size();
//        }
    }
//
//    class GoodsBzTabRvViewHolder extends RecyclerView.ViewHolder{
//        RecyclerView rv;
//        public GoodsBzTabRvViewHolder(@NonNull View itemView) {
//            super(itemView);
//            rv = itemView.findViewById(R.id.goods_Bz_Rv1);
//        }
//    }

    class GoodsBzTitleViewHolder extends RecyclerView.ViewHolder {
        TextView tv;

        //        ImageView img;
        public GoodsBzTitleViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.goods_Item_tv);
//            img = itemView.findViewById(R.id.goods_Bz_SelectorImg);
        }
    }

//    public void addItemNums(int num) {
//        itemCount = num;
//    }
}
